<div class="panel panel-default panel-intro">
    {:build_heading()}

    <div class="panel-body">
        <div id="myTabContent" class="tab-content">
            <div class="tab-pane fade active in" id="one">
                <div class="widget-body no-padding">
                    <div id="toolbar" class="toolbar">
                        <div style="display: flex;align-items: center">
                            <label for="" style="width: 100px;margin-right: 10px">扫码枪销卡:</label>
                            <input type="text" id="barcodeInput" class="layui-input form-control" style="width: 250px">
                        </div>

                    </div>
                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
                           data-operate-edit="{:$auth->check('user_card_log/edit')}"
                           data-operate-del="{:$auth->check('user_card_log/del')}"
                           width="100%">
                    </table>
                </div>
            </div>

        </div>
    </div>
</div>


<script>
    document.getElementById('barcodeInput').addEventListener('change', function () {
        layer.load(2); // 显示加载动画
        var barcodeValue = this.value;
        // 发送请求到后端接口的代码
        fetch('user_card_log/addLog', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({barcode: barcodeValue})
        })
            .then(response => {
                if (!response.ok) {
                    throw new Error('Network response was not ok');
                }
                return response.json();
            })
            .then(data => {
                layer.closeAll(); // 关闭加载动画
                if(data.code === 1){
                    location.reload(); // 刷新页面
                }else {
                    layer.msg(data.msg)
                }

            })
            .catch(error => {

                console.error('Error:', error);
            });
    });
</script>

